package com.tdam2011.grupo04;

import java.util.Date;

import com.tdam2011.grupo04.SMSWeb.ComunicacionServer;
import com.tdam2011.grupo04.entidades.Accion;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;


public class ConnectivityBroadcastReceiver extends BroadcastReceiver {
		
		private static final String TAG = "ConnectivityBroadcastReceiver";
		private NetworkInfo mNetworkInfo;
		
		@Override
		public void onReceive(Context context, Intent intent) {
			
			mNetworkInfo = (NetworkInfo) intent
			.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
			
			if(mNetworkInfo != null){
				Accion accion = new Accion();
				accion.setEstado(mNetworkInfo.getState().toString());
				accion.setTipo(mNetworkInfo.getTypeName());
				Date d = new Date();
				accion.setFecha(d.toString());
				
				Log.w(TAG, "onReceived() called with " + accion.toString()
						+ " and " + intent);
				ArrayAcciones.addAccion(accion);
				
				
				// Si el estado es Conectado activo en envio de mensajes web
				if(mNetworkInfo.getState().toString().equals("CONNECTED"))
					ComunicacionServer.isOnline= true;
				else
					ComunicacionServer.isOnline= false;
			}
		}
}